<?php
/**
 *
 */
namespace Yz\modules\Tasklist;

use Yz_Tree_Default;

class Model_Default
    extends \Yz_Model_Abstract
{


    /** Model's fields definition
     */
    protected function init()
    {
        debug();
        parent::init();
        $d =& $this->__dict__;
        $d['id']         = new \Yz_Property_Id();
        $d['title']      = new \Yz_Property_String();
        $d['href']       = new \Yz_Property_String();
        $d['parent']     = new \Yz_Property_ForeignKey($this);
        return $this;
    }


    public function fetchTree()
    {
        $list = $this->fetchList();
        $tree = new Yz_Tree_Default;
        foreach ($list as $item) {
            $p = $item->parent;
            $tree->createElement($item->id, $item, ($p ? $p->id : null) );
        }
        return $tree;
    }

}
